package cc.messcat.web.fupin;

import java.util.Date;
import java.util.HashMap;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.validation.Valid;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import cc.messcat.common.constant.CommonConstant;
import cc.messcat.common.model.Pager;
import cc.messcat.common.model.ResponseBean;
import cc.messcat.entity.fupin.PoorVillage;
import cc.messcat.entity.system.McUser;
import cc.messcat.service.fupin.PoorVillageService;

/**
 * 
 *贫困村处理管理
 */
@Controller
@RequestMapping("/naorpo")
public class NaturalOrPoorController {

	@Autowired
	private PoorVillageService poorVillageService;
	
	
	/**
	 * 出列查询
	 * @return
	 */
	@RequestMapping("/queryNaOrPo")
	@ResponseBody
	@SuppressWarnings("all")
	public Object queryNaOrPo(Integer pageNo, Integer pageSize,Integer pageNo1, Integer pageSize1,@Valid PoorVillage poorVillage,@RequestParam("year") String year,HttpServletRequest req){
		if (pageNo==null||pageNo<1){
			pageNo=1;
		}
		if (pageSize==null||pageSize<1){
			pageSize=10;
		}
		McUser user = (McUser)req.getSession().getAttribute("user");
		//自然村    (改：已出列贫困村)
		Pager pager = this.poorVillageService.getPoPager3(pageNo1,pageSize1,poorVillage,year,user);
		//贫困村   （改：未列贫困村）
		Pager pager1 = this.poorVillageService.getPoPager2(pageNo,pageSize,poorVillage,year,user);
		Map map = new HashMap<>();
		//未出列贫困村（左）
		map.put("pager", pager);
		//已出列贫困村（右2）
		map.put("pager1", pager1);
		return new ResponseBean(CommonConstant.SUCCESS_CODE_200, CommonConstant.MSG_FIND_SUCCESS, map);
	}
	
	/**
	 * 出列和取消出列的通用方法
	 */
	@RequestMapping("/updatePoor")
	@ResponseBody
	public Object updatePoor(Long id){
			PoorVillage poorVillage = this.poorVillageService.get(id);
			if(poorVillage != null){
				if(poorVillage.getStatus().equals("0")){
					poorVillage.setStatus("1");
					poorVillage.setTuoTime(new Date());
					this.poorVillageService.modifyPoorVillage(poorVillage);
				}else{
					poorVillage.setStatus("0");
					poorVillage.setFanTime(new Date());
					this.poorVillageService.modifyPoorVillage(poorVillage);
				}
		      }
		return new ResponseBean(CommonConstant.SUCCESS_CODE_200, CommonConstant.MSG_SUCCESS);
	}
	
	
}
